/**
* 由libtcc.h导入
*/
module tcc.libtcc;


extern(C){
    enum 
    {
        /// 返回状态异常
        TCC_ERR_FAIL = -1,
        /// output will be run in memory (default)
        TCC_OUTPUT_MEMORY = 1,
        /// executable file
        TCC_OUTPUT_EXE = 2,
        /// dynamic library
        TCC_OUTPUT_DLL = 3,
        /// object file
        TCC_OUTPUT_OBJ = 4,
        /// only preprocess (used internally)
        TCC_OUTPUT_PREPROCESS = 5,

        /**
        possible values for 'ptr':
        - TCC_RELOCATE_AUTO : Allocate and manage memory internally
        - NULL              : return required memory size for the step below
        - memory address    : copy code to memory passed by the caller
        returns -1 if error.
        */
        TCC_RELOCATE_AUTO = cast(void*) 1,

    }
    alias ErrorCallback = void function(void*,void*);
    struct TCCState{}



    /// 创建一个tcc状态
    TCCState *tcc_new() @nogc;

    /// 销毁一个tcc状态
    void tcc_delete(TCCState *s) @nogc;

    /// 设置 CONFIG_TCCDIR
    void tcc_set_lib_path(TCCState *s, in char *path);

    
    /**
    * 设置 错误/警告的回调函数    
    * Params:
    *   s = tcc状态
    *   error_opaque = 错误回调函数的参数
    *   error_func = 错误回调函数
    */
    void tcc_set_error_func(TCCState* s, void* error_opaque,
        void function(void* opaque, in char* msg) error_func);

    
    /**
    * 设置参数选项
    * Params:
    *   s = tcc状态
    *   option = 选项
    */
    void tcc_set_options(TCCState *s, in char *str);

    /**
    * 添加一个include路径
    * Params:
    *   s = tcc状态
    *   pathname = 路径
    */
    int tcc_add_include_path(TCCState *s, in char *pathname);

    /**
    * 添加一个系统用include路径
    * Params:
    *   s = tcc状态
    *  pathname = 系统路径
    */
    int tcc_add_sysinclude_path(TCCState *s, in char *pathname);

    /**
    * 定义一个预处理符号
    * Params:
    *  s = tcc状态
    *  sym = 符号
    *  value = 值
    */
    void tcc_define_symbol(TCCState *s, in char *sym, in char *value);

    /**
    * 取消定义一个预处理符号
    * Params:
    *  s = tcc状态
    *  sym = 符号
    */
    void tcc_undefine_symbol(TCCState *s, in char *sym);

    /**
    * 添加一个文件, 可以是C文件, dll, object, library, ld script
    * Params:
    *  s = tcc状态
    *  filename = 文件名
    * Return:
    *  -1: 失败
    */
    int tcc_add_file(TCCState *s, in char *filename);

    /**
    * 编译C代码字符串字符串
    * Params:
    *  s = tcc状态
    *  str = 字符串
    */
    int tcc_compile_string(TCCState *s, in char *str);

    /**
    * 设置输出类型
    * Params:
    *  s = tcc状态
    *  output_type = 输出类型
    */
    int tcc_set_output_type(TCCState *s, int output_type);

    /**
    * 设置库路径
    * Params:
    *  s = tcc状态
    *  pathname = 路径
    */
    int tcc_add_library_path(TCCState *s, in char *pathname);

    /**
    * 附加一个库
    * Params:
    *  s = tcc状态
    *  libraryname = 库名
    */
    int tcc_add_library(TCCState *s, in char *libraryname);

    /**
    * 增加一个已定义符号到解释器
    * Params:
    *  s = tcc状态
    *  name = 符号名
    *  addr = 地址
    */
    int tcc_add_symbol(TCCState *s, in char *name, const void *val);

    /**
    * 输出一个可执行文件, 库或者对象文件, 请不要在调用tcc_relocate()之前调用
    * Params:
    *  s = tcc状态
    *  filename = 文件名
    */
    int tcc_output_file(TCCState *s, in char *filename);

    /// link and run main() function and return its value. DO NOT call tcc_relocate() before. 
    /**
    * 链接并运行main()函数并返回其值, 请不要在调用tcc_relocate()之前调用
    * Params:
    *  s = tcc状态
    *  argc = 参数个数
    *  argv = 参数列表
    */
    int tcc_run(TCCState *s, int argc, char **argv);

    /**
    * 重定位[???],在使用tcc_get_symbol()之前调用
    * Params:
    *  s = tcc状态
    */
    int tcc_relocate(TCCState *s1, void *ptr);

    /**
    * 获取一个代码中定义的符号
    * Params:
    *  s = tcc状态
    *  name = 符号名
    */
    void *tcc_get_symbol(TCCState *s, in char *name);

}

